#include <iostream>
#include <string>

using namespace std;
const int pos = 0;
string s = "1*1+2*2$";

void eat(){
	s = s.substr(1);
}
 
void error(){
	cout << "failed to match!" << endl;
	exit(1);
}


/* 
 * U->(E) | n
 * M->U*U
 * E->M+M
 */
void U();
void M();
void E();

void U() {
    switch (s[pos]) {
        case '$':
            break;
        case '(':
            eat();
            E();
            if (s[pos]==')') {
                eat();
                break;
            } else {
                error();
            }
            break;
        case '1': case '2': case '3': case '4': case '5':
            eat();
            break;
        default:
            error();
    }
}

void M() {
    switch (s[pos]) {
        case '$':
            break;
        case '(': case '1': case '2': case '3': case '4': case '5':
            U();
            if (s[pos] == '*') {
                eat();
            } else {
                error();
            }
            U();
            break;
        default:
            error();
    }
}

void E() {
    switch (s[pos]) {
        case '$':
            break;
        case '(': case '1': case '2': case '3': case '4': case '5':
            M();
            if (s[pos] == '+') {
                eat();
            } else {
                error();
            }
            M();
            break;
        default:
            error();
    }
}

int main() {
    E();
    cout << s << endl;
}